package kr.hkit.powerjava.chapter24.work2.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.chapter24.work2.dao.InterfaceDAO;
import kr.hkit.powerjava.chapter24.work2.vo.Department;
import kr.hkit.powerjava.chapter24.work2.vo.Student;

@SuppressWarnings("unused")
public class ServiceStudent extends ServiceItem<Student>{

	public ServiceStudent(InterfaceDAO<Student> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Student inputItemInfo(boolean gubun) {
		System.out.print("학번 이름");
		
		Student std = new Student(sc.nextInt(), sc.next().trim());
		
		if(gubun) {
			System.out.print("국어 영어 수학");
			std.setKor(sc.nextInt());
			std.setEng(sc.nextInt());
			std.setMath(sc.nextInt());
		}
		
		return std;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1.이름순 정렬2.성적순정렬 3.번호별 정렬");
		int res = sc.nextInt();
		switch(res) {
			case 1:
				dao.prnListItem(new Comparator<Student>() {
					@Override
					public int compare(Student o1, Student o2) {
						return o1.getStdName().hashCode() - o2.getStdName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnListItem(new Comparator<Student>() {
					@Override
					public int compare(Student o1, Student o2) {
						return o1.totalScore() - o2.totalScore();
					}
				});
				break;
			default :
				dao.prnListItem(null);
		}
	}
}